package cn.it.controller;

import cn.it.domain.Business;
import cn.it.domain.Good;
import cn.it.services.IGoodServices;
import cn.it.util.MyException;
import cn.it.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class TypeGoodsController {
    @Autowired
    private IGoodServices iGoodServices;
    @RequestMapping(value = "/queryGoodsByType")
    public Object queryGoodsByType(Integer typeId) {
        System.out.println(" __________" + typeId);
        HashMap<String,Object> map = new HashMap<>();
        List<Good> goods = null;
        try {
            goods = iGoodServices.queryGoodsByType(typeId);
            map.put("code",200);
            map.put("msg","查询成功");
            map.put("data",goods);
        } catch (MyException e) {
            map.put("code",201);
            map.put("msg",e.getMessage());
            map.put("data",null);
        }
        if (goods == null){
            return "错误";
        }
//        for (Good good : goods) {
//            System.out.println(good.toString());
//        }
        return map;
    }

    @RequestMapping(value = "/queryGoodsById")
    public Result queryGoodsById(Integer id){
        System.out.println("商品Id为-----------"+id);
        Result result = iGoodServices.queryGoodsById(id);
        return result;
    }
}
